<!DOCTYPE html>
<html lang="zh-CN">
<style type="text/css">
    .title4 {
        color: #fafafa;

        letter-spacing: 0;

        font-size: 50px;

        text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;

    }
    .box {
        background-color: #FFF;
        border-radius: 5px;
        border: 1px solid #DDD;
        padding: 30px 20px;
        margin: 50px 10% 20px 10%;
        width: 80%;
        height: 400px;
        text-align: center;

    }

    .box:hover {
        box-shadow: 0 0 5px 3px #CCC;
    }
    .table11_7 table {
        width:100%;
        margin:15px 0;
        border:0;
    }
    .table11_7 th {
        background-color:#00A5FF;
        color:#FFFFFF
    }
    .table11_7,.table11_7 th,.table11_7 td {
        font-size:0.95em;
        text-align:center;
        padding:4px;
        border-collapse:collapse;
    }
    .table11_7 th,.table11_7 td {
        border: 1px solid #2087fe;
        border-width:1px 0 1px 0;
        border:2px inset #ffffff;
    }
    .table11_7 tr {
        border: 1px solid #ffffff;
    }
    .table11_7 tr:nth-child(odd){
        background-color:#aae1fe;
    }
    .table11_7 tr:nth-child(even){
        background-color:#ffffff;
    }
</style>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>类别下新闻</title>

    <link rel="stylesheet" href="../../Public/Css/index.css">
</head>

<body>


    <nav class="navbar">
        <div class="container navbar-content">
            <ul id="menu">
                <li>
                    <a href=""> 首页</a>
                </li>
                <li>
                    <a href=""> 排行</a>
                </li>
                <li>
                    <a href=""> 分类浏览</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
        </div><!-- /.container-fluid -->
    </nav>


<h1 align="center" class="title4">&nbsp;&nbsp;&nbsp;新闻发布系统</h1>
    <div class="box">
            <?php
            echo "<table align=\"center\" class=table11_7 width=\"500\">";
            include_once("../../Functions/connectDatabase.php");
            include_once("../../Functions/page.php");
            get_connection();
            $id = $_REQUEST["id"];
            $sql = "SELECT * FROM news WHERE category_id ='$id'";
            $result = mysqli_query($conn, $sql);
            $total_records = mysqli_num_rows($result);
            $page_size = 5;
            if(isset($_GET["page_current"])){
                $page_current = $_GET["page_current"];
            }else{
                $page_current = 1;
            }
            $start = ($page_current-1)*$page_size;
            $sql = "SELECT * FROM news WHERE category_id ='$id' order by news_id desc limit $start,$page_size";
            $result = mysqli_query($conn, $sql);
            
            echo "<tr><th>标题</th><th>类别</th><th>发布时间</th><th>发布者</th><th>点击数</th><th>操作</th></tr>";
            if (mysqli_num_rows($result) > 0) {
                while ($row = mysqli_fetch_assoc($result)) {
                    echo "<tr>";
                    echo "<td><a href=\"./newsShow.php?id=" . $row["news_id"] ."\">". $row["news_title"]."</td>";
                    $sql = "SELECT category_name FROM category WHERE category_id='" . $row['category_id'] . "'";
                    $re = mysqli_query($conn, $sql);
                    $r2 = mysqli_fetch_assoc($re);
                    echo "<td><a href=\"./newsShow.php?id=" . $row["category_id"] ."\">". $r2["category_name"]."</td>";
                    echo "<td>" . $row["news_publish_time"] . "</td>";
                    $sql = "SELECT user_name FROM users WHERE user_id='" . $row['user_id'] . "'";
                    $re = mysqli_query($conn, $sql);
                    $r1 = mysqli_fetch_assoc($re);
                    echo "<td>" . $r1["user_name"] . "</td>";
                    echo "<td>" . $row["news_clicked"] . "</td>";
                    echo "<td colspan=\"2\"><a href=\"./Modify_V.php?id=" . $row["news_id"] . "\">修改</a>";
                    echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    echo "<a href=\"./Delete_V.php?id=" . $row["news_id"] . "\">删除</a></td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan=\"6\">暂无新闻</td><tr>";
            }
            $url = $_SERVER["PHP_SELF"];
            page($total_records,$page_size,$page_current,$url,"");
            echo "<br><h2>新闻列表</h2>";
            echo "<a href=\"./Add_V.php\">添加一个新闻</a>";
            echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"./Search_V.php\">搜索新闻</a>";
            echo "<br><br>";
            close_connection();
            echo "</table>";
            ?>
        
    </div>
    
    </form>

</body>

</html>